﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using LZL;

namespace ConsoleTest
{
    using ConsoleTest.Code;
    using System.Collections.ObjectModel;

    class NQ
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string age { get; set; }
        public List<object> list { get; set; }
        public NQ Copy()
        {
            return (NQ)this.MemberwiseClone();
        }
    }

    class NQEditCompare : IEqualityComparer<NQ>
    {

        public bool Equals(NQ x, NQ y)
        {
            return x.ID == y.ID && (x.Name != y.Name || x.age != y.age);
        }

        public int GetHashCode(NQ obj)
        {
            return 0;
        }
    }
    class NQCompare : IEqualityComparer<NQ>
    {

        public bool Equals(NQ x, NQ y)
        {
            return x.ID == y.ID && x.ID != 0;
        }

        public int GetHashCode(NQ obj)
        {
            return 0;
        }
    }
    [Flags]
    enum tt : byte
    {
        none = 0,
        a = 1,
        q = 2,
        w = 4,
        e = 8
    }
    class Program
    {
        public static string FVTimeZoneId = "Pacific Standard Time";

        static void Test(object obj)
        {
            obj = "1";
        }
        static void Main(string[] args)
        {
            TestRazor.Test();

            //NQ nq = new NQ()
            //{
            //    age = "1",
            //    ID = 1,
            //    Name = "1",
            //    list = new List<object>() { 1,2,3}

            //};
            //NQ nq2 = nq.Copy();
            //Console.WriteLine(nq.ToJson());
            //Console.WriteLine(nq2.ToJson());
            //nq.Name = "120";
            //nq.list.Add(1);
            //nq2.age = "age";
            //Console.WriteLine(nq.ToJson());
            //Console.WriteLine(nq2.ToJson());
            //tt t = tt.none | tt.w | tt.q;
            //var list = new List<NQ>();
            //Console.WriteLine(list.Any() ? list.Max(p => p.ID) : 0);
            //switch (t)
            //{
            //    case tt.none:
            //        Console.WriteLine(t);

            //        break;
            //    case tt.q:
            //        Console.WriteLine(t);
            //        break;
            //    case tt.w:
            //        Console.WriteLine(t);
            //        break;
            //    case tt.e:
            //        Console.WriteLine(t);
            //        break;
            //    default:
            //        throw new ArgumentOutOfRangeException();
            //}
            //  object obj = 2;
            // Test(obj);
            // Console.WriteLine(obj);
            // List<NQ> left = new List<NQ>() { new NQ() { ID = 0 }, new NQ() { ID = 0 }, new NQ() { ID = 2, age = "1" }, new NQ() { ID = 3 } };
            // List<NQ> right = new List<NQ>() { new NQ() { ID = 3 }, new NQ() { ID = 2 }, new NQ() { ID = 5 } };
            // var list = left.Intersect(right, new NQCompare());
            //// var list1 = list.Intersect(right, new NQEditCompare());
            // var list2 = left.Except(list, new NQCompare());
            // // var list = left.Join(right, p1 => p1.ID, p2 => p2.ID, (p1, p2) => new { left = p1.ID, right = p2.ID });
            // Console.WriteLine(list.ToJson());
            //// Console.WriteLine(list1.ToJson());
            // Console.WriteLine(list2.ToJson());
            //var dict = new DictCollection() { new Dict { Name = "t1" }, new Dict { Name = "t2" },
            //new Dict { Name = "t1" }, new Dict { Name = "t2" },new Dict { Name = "t1" }, new Dict { Name = "t2" },
            //new Dict { Name = "t1" }, new Dict { Name = "t2" },new Dict { Name = "t1" }, new Dict { Name = "t2" }};
            //Console.WriteLine(dict.Test());
            //Console.WriteLine(AutoNum().ToJson());
            //IList<int> t = new List<int> { 1, 21, 3 };
            //Console.WriteLine(t.ToString((p) => p.ToString()+","));
            Console.ReadKey();
        }

        public static string GetList<T>(List<T> source, Func<T, string> action)
        {
            if (source == null)
            {
                return null;
            }
            if (source.Count == 0)
            {
                return string.Empty;
            }
            if (source.Count == 1)
            {
                return action(source[0]);
            }
            StringBuilder sb = new StringBuilder();
            foreach (var item in source)
            {
                sb.Append(action(item));
            }
            return sb.ToString();
        }
        public static IEnumerable<string> AutoNum(int num = 10)
        {
            int i = 0;
            while (i < num)
            {
                yield return i.ToString();
                i++;
            }
        }
        public static object GetModel(Type type)
        {
            if (type.IsGenericType)
            {
                Type t = type.GetGenericTypeDefinition();
                Type t2 = typeof(IList<>);
                var ttt = type.GetGenericArguments();
                if (t == typeof(Dictionary<,>))
                {
                    type = typeof(Dictionary<,>).MakeGenericType(type.GetGenericArguments());
                }
                else if (t == typeof(IEnumerable<>) || t == typeof(Collection<>) || t == typeof(List<>))
                {
                    type = typeof(List<>).MakeGenericType(type.GetGenericArguments());
                }
            }
            return Activator.CreateInstance(type);
        }

        public static DateTime ConvertTime(DateTime inDateTime, string sourceTimeZoneId, string destTimeZoneId)
        {
            if (inDateTime == DateTime.MinValue)
            {
                return inDateTime;
            }

            inDateTime = DateTime.SpecifyKind(inDateTime, DateTimeKind.Unspecified);
            return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(inDateTime, sourceTimeZoneId, destTimeZoneId);
        }
    }
}
